
#include "main.h" 

void main(void)
{
	char s1[32];
	char s2[32];
	uint16_t tmp;
	uint16_t year;

	CLK_DeInit();
	CLK_HSICmd(ENABLE);
	CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1); // 16MHz
	CLK_ClockSecuritySystemEnable();

	lcd_init();
	DS1302_Init();
	key_init();       
	led_init();
	eeprom_init();
	sensor_init();
	//TM1638_Init();

	InitTim1();
	//InitTim2();
	//InitTim4();

	enableInterrupts();  // enable all interrupts

	// read parameter from eeprom
	sensor_save_cnt = eeprom_read(EE_ADDR_CNT);

	// Write year
	year = DS1302_ReadReg(DS1302_ADDR_YEAR);
	eeprom_write(EE_ADDR_YEAR, year);

	activeRecord = sensor_save_cnt;
	ShowRecord(activeRecord);

	//DS1302_WriteReg(DS1302_ADDR_CTRL, 0x00);
	//DS1302_WriteReg(DS1302_ADDR_SECONDS, 0x80);
	//DS1302_SetTime(0x15, 0x02, 0x11, 0x21, 0x39, 0x00);

	while (1)
	{
		// lcd_set_row(0);
		// DS1302_ReadTime(&my_time);
		// sprintf(s1, "%02X%02X%02X %02X:%02X:%02X",
		//  	DS1302_ReadReg(DS1302_ADDR_YEAR),
		//  	DS1302_ReadReg(DS1302_ADDR_MONTH),
		//  	DS1302_ReadReg(DS1302_ADDR_DAYoM),
		//  	DS1302_ReadReg(DS1302_ADDR_HOURS),
		//  	DS1302_ReadReg(DS1302_ADDR_MINUTES),
		//  	DS1302_ReadReg(DS1302_ADDR_SECONDS));
		// lcd_print(s1);
		// lcd_set_row(1);
		// sprintf(s2, "%02X %02X %02X",
		// 	DS1302_ReadReg(DS1302_ADDR_CTRL),
		// 	DS1302_ReadReg(DS1302_ADDR_CLK),
		// 	DS1302_ReadReg(DS1302_ADDR_CHARGE)
		// 	);
		// lcd_print(s2);
		// delay(5000);
	}
	
}


#ifdef USE_FULL_ASSERT

/**
  * @brief  Reports the name of the source file and the source line number
  *   where the assert_param error has occurred.
  * @param file: pointer to the source file name
  * @param line: assert_param error line source number
  * @retval : None
  */

void assert_failed(u8* file, u32 line)
{ 
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  /* Infinite loop */
  while (1)
  {
  }
  
}

#endif